﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Objects;
using BAL;

public partial class Admin_Duyet_Update : System.Web.UI.Page
{
    public static DanhSachChoDuyet itemChoDuyet;
    public static NguoiDung itemNguoidung;

    public static Duyet itemDuyet;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            itemChoDuyet = new DanhSachChoDuyet();
            itemChoDuyet = (DanhSachChoDuyet)Session["ItemDuyet"];

            itemNguoidung = new NguoiDung();
            itemNguoidung = (NguoiDung)Session["ItemDangNhap"];

            itemDuyet = new Duyet();

            if (itemChoDuyet != null)
            {
                itemDuyet = BALDuyet.GetById(itemChoDuyet.Id);
            }

            //txtNhanThe.Text = DateTime.Now.ToShortDateString();

        }
    }

    protected void btnDuyet_Click(object sender, EventArgs e)
    {
      

        int item = 0;

        item = BALDuyet.Update_Duyet(itemDuyet.Id, itemDuyet.IdDangKy, itemNguoidung.Id, DateTime.Now, txtGhiChu.Text,Common.Myconst.DUYET, 1, itemDuyet.SapXep);

        //if (txtNhanThe.Text != "" && txtHetHan.Text != "")
        //{

        //    item = BALDuyet.Update_Duyet(itemDuyet.Id, itemDuyet.IdDangKy, itemNguoidung.Id, DateTime.Now, txtGhiChu.Text, 1, 1, 0);

        //}

        //if (txtNhanThe.Text == "")
        //{
        //    lblNhanThe.Visible = true;
        //    txtNhanThe.Focus();
        //}

        //if (txtHetHan.Text == "")
        //{
        //    lblHetHan.Visible = true;
        //    txtHetHan.Focus();
        //}

        if (item > 0)
        {
            lblThongBao.Text = "Duyệt thành công";
        }
        else
        {
            lblThongBao.Text = "Duyệt thất bại";
        }

    }

    //private void CapNhapDangKy()
    //{
    //     DangKy itemDangKy = new DangKy();
    //     itemDangKy = BALDangKy.GetById(itemDuyet.IdDangKy);

    //     itemDangKy.NgayNhanThe = Convert.ToDateTime(txtNhanThe.Text);
    //     itemDangKy.NgayHetHan = Convert.ToDateTime(txtHetHan.Text);

    //     BALDangKy.Update(itemDangKy);
        
    //}

    protected void btnKhongduyet_Click(object sender, EventArgs e)
    {
        int item;
        item = BALDuyet.Update_Duyet(itemDuyet.Id, itemDuyet.IdDangKy, itemNguoidung.Id, DateTime.Now, txtGhiChu.Text,Common.Myconst.KHONGDUYET, 1, itemDuyet.SapXep);
        if (item > 0)
        {
            lblThongBao.Text = "Duyệt thành công";
        }
        else
        {
            lblThongBao.Text = "Duyệt thất bại";
        }
    }
}
